package org.example.ims.Controller.WarehouseProduct;

import org.example.ims.DTO.InventoryItemDTO;
import org.example.ims.DTO.ProductWithInventoryDTO;
import org.example.ims.DTO.Response;
import org.example.ims.Service.WarehouseProduct.WarehouseProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/warehouseProduct")
public class WarehouseProductController {

    @Autowired
    private WarehouseProductService warehouseProductService;

    //warehouseId,status=active,stock大于0,用于给出库单查询该仓库中商品信息
    @GetMapping("/{warehouseId}")
    public Response<Page<ProductWithInventoryDTO>> searchProducts(
            @PathVariable Integer warehouseId,
            @RequestParam(required = false,defaultValue = "active") String status,
            @RequestParam(defaultValue = "0") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        return Response.success(warehouseProductService.searchProducts( warehouseId,status,page, size));
    }
    //对于库存管理中的复杂查询，相当于上面的升级版本
    @GetMapping
    public Response<Page<InventoryItemDTO>> queryInventory(
            @RequestParam(required = false) Integer warehouseId,
            @RequestParam(required = false) Integer categoryId,
            @RequestParam(required = false) String productStatus,
            @RequestParam(required = false) String productName,
            @RequestParam(required = false) Integer minStock,
            @RequestParam(required = false) Integer maxStock,
            @RequestParam(defaultValue = "0") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        return Response.success(warehouseProductService.queryInventory(warehouseId,categoryId,
                productStatus,productName,minStock,maxStock, page, size));
    }
}
